//
//  LJFNewHotViewController.m
//  GiftThat
//
//  Created by 刘景峰 on 16/1/8.
//  Copyright © 2016年 ChuXiang. All rights reserved.
//

#import "LJFNewHotViewController.h"
#import "TFHpple.h"
#import "UMSocial.h"
@interface LJFNewHotViewController ()<UIWebViewDelegate,UMSocialUIDelegate>

@end

@implementation LJFNewHotViewController

-(void)viewWillAppear:(BOOL)animated{
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
        [self creatWebView];
//    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
//    [self.navigationItem.leftBarButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];、

    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"share"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(shareURLString)];
    
    self.navigationItem.rightBarButtonItem = item;
    
    self.navigationItem.title = @"礼物详情";
    [self creatWebView];
    
    
    
}

-(void)shareURLString{
    
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"507fcab25270157b37000010"
                                      shareText:self.urlString                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToQQ,UMShareToTencent,nil]
                                       delegate:self];
    
}
-(BOOL)isDirectShareInIconActionSheet{
    return YES;
}
//-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response{
//    if (response.responseCode == UMSResponseCodeSuccess) {
//    
//    }
//}
-(void)creatWebView{
    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - 113)];
    webView.delegate = self;
    webView.scalesPageToFit = YES;
    
    [CXNetWorkTool getWithUrl:self.urlString parameter:nil httpHeader:nil responseType:ResponseTypeDATA success:^(id result) {
        NSString *str = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
        //    解析html数据
        TFHpple *xpathParser = [[TFHpple alloc]initWithHTMLData:result];
        //    根据标签进行过滤
        NSArray *dataArray = [xpathParser searchWithXPathQuery:@"//div"];

        for (TFHppleElement *hppleElement in dataArray) {
            if ([hppleElement.attributes[@"class"] isEqualToString:@"wrapper download-banner"]) {
                //            根据节点属性获取广告，在用如下方法置换为空
                str = [str stringByReplacingOccurrencesOfString:hppleElement.raw withString:@""];
            }
        }
        [webView loadHTMLString:str baseURL:[NSURL URLWithString:self.urlString]];

    } fail:^(NSError *error) {
        NSLog(@"%@",error);
    }];

    [self.view addSubview:webView];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
